


import java.math.*;
import java.util.HashMap;
import java.lang.reflect.Field;

public class Reactor1 extends SplitSimSystem{
	private double upperLimit;
	private double lowerLimit;
	private double temp=300;
	private double moistureContent=100;
	private double collisionSpeed=220;
	private double collisionRate=520;
	private int leakageFactor=0;
	
	public void Reactor1(){
	}
	
	public void initialize(double upperLimitInput, double lowerLimitInput, HashMap<String,Double> stateInput){
		upperLimit=upperLimitInput;
		lowerLimit=lowerLimitInput;
		temp=stateInput.get("temp");
		super.poi=temp;
		setStartPar(300.0);
		setMaxPar(400.0);
	}
	
	//implementation of SplitSim Abstract Class setState
	public void setState(){
		state.put("temp", temp);
		state.put("moistureContent", moistureContent);
		state.put("collisionSpeed", collisionSpeed);
		state.put("collisionRate", collisionRate);
	}
	
	public boolean run(){
		//leakageFactor
		for (int runCount=0; runCount<1000000000;runCount++){
			leakageFactor = (int)(Math.random()*1000);
			
			if (temp>390 && leakageFactor>=997){
				moistureContent++;
				temp=temp+1;
			}
			else if (temp<=390 && leakageFactor>=999){
				moistureContent++;
				temp=temp+1;
			}
			if (leakageFactor<500){
				moistureContent--;
				temp=temp-1;
			}
			if (leakageFactor<500){
				moistureContent--;
				temp=temp-1;
			}
			if (leakageFactor>=509){
				collisionSpeed++;
			}
			if (leakageFactor<500){
				collisionSpeed--;
			}
			if (leakageFactor>=525){
				collisionRate++;
			}
			if (leakageFactor<500){
				collisionRate--;
			}
			
			syncLevel();
			
			super.poi=temp;
			
			if (temp>=upperLimit){
				return true;
			}
			else if (temp<lowerLimit){
				return false;
			}
			
		}
		return false;
	}
	

}
